<%@ page language="java" import="java.util.*,com.hs.core.db.*" pageEncoding="UTF-8"%>
<%@ page import="cn.ac.cintcm.dataconverge.dataAnalyze.form.*,cn.ac.cintcm.dataconverge.researcher.domain.*,
java.util.Map.Entry,com.hs.core.page.PageUtil,com.hs.core.utils.StringUtilTool,cn.ac.cintcm.dataconverge.util.Constants" %>
<%@ page import="org.jfree.chart.ChartFactory,
org.jfree.chart.JFreeChart,
org.jfree.chart.labels.StandardCategoryItemLabelGenerator,
org.jfree.chart.plot.CategoryPlot,
org.jfree.chart.plot.PlotOrientation,
org.jfree.chart.renderer.category.BarRenderer3D,
org.jfree.chart.servlet.ServletUtilities,
org.jfree.data.category.DefaultCategoryDataset,java.awt.Font" %>
<%
String path = request.getContextPath();
String belongyear = request.getParameter("belongyear");
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
DBOperator dbo = new DBOperator(request.getSession().getServletContext());
		DefaultCategoryDataset dataset3=new DefaultCategoryDataset ();	
		DefaultCategoryDataset dataset4=new DefaultCategoryDataset ();	
		String sqlTag = "SELECT TO_CHAR(ID) AS TAGID,NAME FROM resman_tag WHERE PARENTID=1 order by SIBLINGSEQ";
		String countSql = "SELECT SUM (s.permitfund) AS ALLFUND, COUNT (*) AS ALLCOUNT  FROM resman_subject_tag st LEFT JOIN resman_subject s ON st.subjectid = s.ID WHERE st.tagid IN (SELECT     ID FROM resman_tag CONNECT BY PRIOR ID = parentid  START WITH ID = ?) ";
		if(null != belongyear)
		    countSql +="and s.belongyear=?"; 
		List tagList = dbo.select(sqlTag, null);
		for(int i =0;i<tagList.size();i++){
			Map m = (Map)tagList.get(i);
			String tagId = (String)m.get("TAGID");
			String tagName= (String)m.get("NAME");
			List dataList = null;
			if(null != belongyear)
			   dataList = dbo.select(countSql, new Object[]{tagId,belongyear});
			   else
			    dataList = dbo.select(countSql, new Object[]{tagId});
			Map data = (Map)dataList.get(0);
			int allCount = ((java.math.BigDecimal)data.get("ALLCOUNT")).intValue();
			Object fund = data.get("ALLFUND"); 
			double allFund = 0;
			if(null != fund)
			    allFund = ((java.math.BigDecimal)fund).doubleValue();
			    System.out.println("allcount:" + allCount);
			    System.out.println("allFund:" + allFund);
			dataset3.addValue(allCount, tagName, "");
			dataset4.addValue(allFund, tagName, "");
		}
		
		JFreeChart chart3 = ChartFactory.createBarChart3D("课题分类数目分布",
				"",
				"课题数量",dataset3,
				PlotOrientation.VERTICAL,
				true,
				false,
				false);
		
		  	CategoryPlot plot3=(CategoryPlot)chart3.getPlot();
		  	BarRenderer3D   renderer3   =   new   BarRenderer3D(); 
		    renderer3.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
		    renderer3.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
		    renderer3.setItemLabelsVisible(true);			  
		    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
		    plot3.setRenderer(renderer3);
		    JFreeChart chart4 = ChartFactory.createBarChart3D("课题分类经费分布",
					"",
					"经费金额",dataset4,
					PlotOrientation.VERTICAL,
					true,
					false,
					false);
			
			  	CategoryPlot plot4=(CategoryPlot)chart4.getPlot();
			  	BarRenderer3D   renderer4   =   new   BarRenderer3D(); 
			    renderer4.setItemLabelGenerator(new StandardCategoryItemLabelGenerator());
			    renderer4.setItemLabelFont(new Font("黑体",Font.PLAIN,12));
			    renderer4.setItemLabelsVisible(true);			  
			    //renderer.setLegendItemLabelGenerator(new StandardCategorySeriesLabelGenerator("{0}"));
			    plot4.setRenderer(renderer4);
			    String filename = ServletUtilities.saveChartAsPNG(chart3,500,300,null,request.getSession());
		String graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
		request.getSession().setAttribute("graphURL", graphURL);
		request.getSession().setAttribute("filename", filename);	
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'imageSubject.jsp' starting page</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    <table cellspacing="0" cellpadding="0" width="100%" class="idt_bottom_mg" border="0">
           
          <tr>
              <td align="center">  
              <img src="<%=graphURL%>" style="width:99%"></img>
              </td>
              <td align="center"> 
               <%
              filename = ServletUtilities.saveChartAsPNG(chart4,500,300,null,request.getSession());
      		  graphURL = request.getContextPath() + "/DisplayChart?filename=" + filename;
      		  request.getSession().setAttribute("graphURL", graphURL);
      		  request.getSession().setAttribute("filename", filename);
               
              %>
              <img src="<%=graphURL%>" style="width:99%"></img>
              </td>
              
          </tr>
    </table>
  </body>
</html>
